home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / PowerPlant / AMReminder / CMainWindow.cp < prev    next >
Encoding:
Text File  |  1996-03-19  |  4.1 KB  |  235 lines  |  [TEXT/CWIE]

  1. // CMainWindow.cp -- window methods
  2. // Created 3/19/96 1:49 PM by AppMaker
  3.  
  4. #include "CMainWindow.h"
  5.  
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LListBox.h>
  10. #include <LStdControl.h>
  11. #include "CAMReminderData.h"
  12. #include "CAdd.h"
  13. #include "CmdCodes.h"
  14.  
  15. #define PPob_MainWindowID    200
  16. #define RidL_MainWindowID    200
  17.  
  18. Boolean        CMainWindow::sIsRegistered = false;
  19.  
  20. //----------
  21. void
  22. CMainWindow::RegisterClass ()
  23. {
  24.     URegistrar::RegisterClass ('Main', (ClassCreatorFunc)CMainWindow::CreateMainWindowStream);
  25.  
  26.     // register the pane classes we use
  27.  
  28.     sIsRegistered = true;
  29. }
  30.  
  31. //----------
  32. CMainWindow*
  33. CMainWindow::CreateMainWindow(
  34.     LCommander            *inSuperCommander,
  35.     CAMReminderData        *inData)
  36. {
  37.     if (!sIsRegistered) {
  38.         RegisterClass ();
  39.     }
  40.  
  41.     CMainWindow        *window;
  42.  
  43.     window = (CMainWindow *)LWindow::CreateWindow(PPob_MainWindowID, inSuperCommander);
  44.     window->ConnectToData (inData);
  45.  
  46.     return window;
  47. }
  48.  
  49. //----------
  50. //    This is the function you register with URegistrar to create a
  51. //    CMainWindow from a resource
  52.  
  53. CMainWindow*
  54. CMainWindow::CreateMainWindowStream(
  55.     LStream    *inStream)
  56. {
  57.     return (new CMainWindow(inStream));
  58. }
  59.  
  60. //----------
  61. CMainWindow::CMainWindow()
  62. {
  63. }
  64.  
  65. //----------
  66. CMainWindow::CMainWindow(
  67.     LStream    *inStream)
  68.         : LWindow(inStream)
  69. {
  70. }
  71.  
  72. //----------
  73. CMainWindow::~CMainWindow()
  74. {
  75. }
  76.  
  77. //----------
  78. //    This member function gets called once the containment hierarchy that contains
  79. //    this pane has been built. It gives us a chance to get data members for
  80. //    interesting subviews, and to do other operations now that our subviews exist.
  81. void
  82. CMainWindow::FinishCreateSelf()
  83. {
  84.     mRemindersList = (LListBox *)FindPaneByID('Remi');
  85.     mAddButton = (LStdButton *)FindPaneByID ('Add ');
  86.     mEditButton = (LStdButton *)FindPaneByID ('Edit');
  87.     mDeleteButton = (LStdButton *)FindPaneByID ('Dele');
  88.  
  89.     UReanimator::LinkListenerToControls(this, this, RidL_MainWindowID);
  90.         // the purpose is to "connect" self to whatever controls
  91.         // that we want to "listen" to
  92.  
  93. // any additional initialization for your window:
  94.  
  95. }
  96.  
  97. //----------
  98. void
  99. CMainWindow::ConnectToData    (CAMReminderData        *inData)
  100. {
  101.     mData = inData;
  102.     inData->AddListener (this);
  103. }
  104.  
  105. //----------
  106. void
  107. CMainWindow::DoAddReminder ()
  108. {
  109. CAdd*    dialog = CAdd::CreateAdd(this);
  110. }
  111.  
  112. //----------
  113. void
  114. CMainWindow::DoEditReminder ()
  115. {
  116. CAdd*    dialog = CAdd::CreateAdd(this);
  117. }
  118.  
  119. //----------
  120. void
  121. CMainWindow::DoDeleteReminder ()
  122. {
  123. }
  124.  
  125. //----------
  126. void
  127. CMainWindow::ObeyAdd    (void*    ioParam)
  128. {
  129. CAdd*    dialog = (CAdd *)ioParam;
  130.  
  131. delete dialog;
  132. }
  133.  
  134. //----------
  135. void
  136. CMainWindow::ListenToMessage(
  137.     MessageT    inMessage,
  138.     void        *ioParam)
  139. {
  140.     switch (inMessage) {
  141.  
  142.     case cmdAddReminder:
  143.         DoAddReminder ();
  144.         break;
  145.  
  146.     case cmdEditReminder:
  147.         DoEditReminder ();
  148.         break;
  149.  
  150.     case cmdDeleteReminder:
  151.         DoDeleteReminder ();
  152.         break;
  153.  
  154.     default:
  155.         break;
  156.     }
  157. }
  158.  
  159. //----------
  160. Boolean
  161. CMainWindow::ObeyCommand(
  162.     CommandT    inCommand,
  163.     void        *ioParam)
  164. {
  165.     Boolean        cmdHandled = true;
  166.  
  167.     switch (inCommand) {
  168.  
  169.     // +++ Add cases here for the commands you handle
  170.     //        Remember to add same cases to FindCommandStatus below
  171.     //        to enable/disable the commands
  172.  
  173.     case cmd_Add:
  174.         ObeyAdd    (ioParam);
  175.         break;
  176.  
  177.     default:
  178.             cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
  179.         break;
  180.     }
  181.  
  182.     return cmdHandled;
  183. }
  184.  
  185. //----------
  186. void
  187. CMainWindow::FindCommandStatus(
  188.     CommandT    inCommand,
  189.     Boolean        &outEnabled,
  190.     Boolean        &outUsesMark,
  191.     Char16        &outMark,
  192.     Str255        outName)
  193. {
  194.     outUsesMark = false;
  195.  
  196.     switch (inCommand) {
  197.  
  198.     // +++ Add cases here for the commands you handle
  199.     case cmdAddReminder:
  200.         outEnabled = true;
  201.         break;
  202.     case cmdEditReminder:
  203.         outEnabled = true;
  204.         break;
  205.     case cmdDeleteReminder:
  206.         outEnabled = true;
  207.         break;
  208.  
  209.     default:
  210.             LWindow::FindCommandStatus(inCommand, outEnabled,
  211.                                         outUsesMark, outMark, outName);
  212.         break;
  213.     }
  214. }
  215.  
  216. //----------
  217. Boolean
  218. CMainWindow::FocusDraw()
  219. {
  220.     Boolean        focused = LView::FocusDraw();
  221.  
  222.     if (focused) {
  223.         AuxWinHandle    awHndl;
  224.         CTabHandle        awCTable;
  225.         ColorSpec        contentSpec;
  226.  
  227.         GetAuxWin(GetMacPort(), &awHndl);
  228.         awCTable = (**awHndl).awCTable;
  229.         contentSpec = (**awCTable).ctTable [wContentColor];        // should search vs. index
  230.         ::RGBBackColor(&contentSpec.rgb);
  231.     }
  232.  
  233.     return focused;
  234. }
  235.